<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{layout}">

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>

    <title th:text="#{cas.mfa.googleauth.pagetitle}">Google Authentication View</title>
    <link href="../../static/css/cas.css" rel="stylesheet" th:remove="tag"/>
</head>

<body>
<main role="main" class="container mt-3 mb-3">
    <div layout:fragment="content" id="login" class="mdc-card mdc-card-content w-lg-50 p-4 m-auto">

        <p th:utext="#{screen.authentication.gauth.selecteddevice(${registeredDevice.name})}"></p>

        <form method="post" id="fm1" th:object="${credential}" th:action="@{/login}">
            <div id="msg" class="banner banner-danger my-2" th:if="${#fields.hasErrors('*')}">
                <span th:each="err : ${#fields.errors('*')}" th:utext="${err + ' '}"/>
            </div>
            <input type="hidden" name="_eventId_submit" value="Login"/>
            <input type="hidden" name="execution" th:value="${flowExecutionKey}"/>
            <input type="hidden" name="geolocation"/>
            <section class="cas-field my-3 mdc-input-group">
                <div class="mdc-input-group-field mdc-input-group-field-append">
                    <div class="d-flex caps-check">
                        <input type="hidden"
                               id="accountId" name="accountId" size="25"
                               autocomplete="off" th:field="*{accountId}"/>
                        
                        <label for="token" class="mdc-text-field mdc-text-field--outlined mdc-text-field--with-trailing-icon">
                            <input class="mdc-text-field__input pwd"
                                   type="password"
                                   name="token"
                                   id="token"
                                   th:field="*{token}"
                                   size="25"
                                   autocomplete="off" required />

                            <span class="mdc-notched-outline">
                                <span class="mdc-notched-outline__leading"></span>
                                <span class="mdc-notched-outline__notch">
                                  <span class="mdc-floating-label" th:utext="#{cas.mfa.googleauth.label.token}">Token</span>
                                </span>
                                <span class="mdc-notched-outline__trailing"></span>
                            </span>
                        </label>

                        
                        <script type="text/javascript" th:inline="javascript">
                            /*<![CDATA[*/
                            let accountId = /*[[${registeredDevice.id}]]*/;
                            document.getElementById("accountId").value = accountId;
                            /*]]>*/
                        </script>
                    </div>
                    <div class="mdc-text-field-helper-line caps-warn">
                        <p class="mdc-text-field-helper-text mdc-text-field-helper-text--persistent mdc-text-field-helper-text--validation-msg text-danger">
                            <span th:utext="#{screen.capslock.on}"/>
                        </p>
                    </div>
                </div>
                <button class="reveal-password mdc-button mdc-button--raised mdc-input-group-append mdc-icon-button" type="button">
                    <i class="mdi mdi-eye reveal-password-icon"></i>
                    <span class="sr-only">Toggle Token</span>
                </button>
            </section>

            <button id="login" class="mdc-button mdc-button--raised" accesskey="l">
                <span class="mdc-button__label" th:text="#{screen.welcome.button.login}">Login</span>
            </button>
            <a class="mdc-button mdc-button--raised" id="cancel" name="cancel"
               onclick="location.href = location.href;">
                <span class="mdc-button__label" th:utext="#{screen.authentication.gauth.cancel}">Cancel</span>
            </a>
        </form>
        <span th:if="${registeredDevices}">
            <p>
            <hr width="75%">
            <p th:utext="#{screen.authentication.gauth.selanotherdevice(${registeredDevice.name})}"></p>
            <form method="post" id="fm3">
                <input type="hidden" name="_eventId_select" value="select"/>
                <input type="hidden" name="execution" th:value="${flowExecutionKey}"/>
                <button id="selectDeviceButton" class="mdc-button mdc-button--raised mr-2" accesskey="s">
                    <span class="mdc-button__label" th:text="#{screen.authentication.gauth.selectdevice}">Select Device</span>
                </button>
            </form>
        </span>
        
        <form method="post" id="fm2" th:if="${gauthMultipleDeviceRegistrationEnabled}">
            <p>
            <hr width="75%">
            <p th:utext="#{screen.authentication.gauth.reganotherdevice}"></p>
            <input type="hidden" name="_eventId_register" value="register"/>
            <input type="hidden" name="execution" th:value="${flowExecutionKey}"/>
            <button class="mdc-button mdc-button--raised mr-2" id="register" type="submit" name="register" accesskey="r" value="Register">
                <span class="mdc-button__label" th:text="#{screen.welcome.button.register}">Register</span>
            </button>
        </form>
        </p>
    </div>
</main>
</body>
</html>
